package jyc_util.a_review.semaphore;

import java.util.Scanner;
import java.util.concurrent.Semaphore;

/**
 * @author haomin
 * @date 2022/09/23 17:43
 **/
public class Main {
    static Semaphore semaphore = new Semaphore(5);
    static class MyThread extends Thread {
        @Override
        public void run() {
            Scanner scanner = new Scanner(System.in);
            scanner.nextLine();
            semaphore.release();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread t = new MyThread();
        t.start();
        semaphore.acquire();
        semaphore.acquire();
        semaphore.acquire();
        semaphore.acquire();
        semaphore.acquire();// 信号量用完
        System.out.println("信号量用完");
        semaphore.acquire();
        System.out.println("子线程释放一个后，所以能再得到一个");
    }
}